using Admin2505.Application.Common.Interfaces;
using Admin2505.Domain.Reposoitories;
using Admin2505.Iinfrastructure.Data;
using Admin2505.Iinfrastructure.Secunity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Admin2505.Iinfrastructure;

public static class ServiceCollectionExtensions
{
    public static IServiceCollection AddInfrastructure (this IServiceCollection services, IConfiguration configuration)
    {
        //注册数据库上下文
       var connectionString = configuration.GetConnectionString("DefaultConnection");

        services.AddDbContext<Admin2505DbContext>(options =>
            options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)) // 使用 MySQL
        );

        //注册仓储接口
        services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>));
        services.AddScoped(typeof(IPasswordHasher), typeof(PasswordHasher));

        return services;
    }
}